

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>{block name="title"}电影网{/block}</title>
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/layer.css">
    <link rel="stylesheet" type="text/css" href="css/swiper.min.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.cookie.js"></script>
    <script src="js/layer.js"></script>
    <script src="js/swiper.min.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
</head>
<body>
  	<div class="nav"></div>
<div class="login-box">
	<div class="login-title">设置</div>
	<div class="login-input">
		<div class="username">
			<label>用户名</label>
			<input type="text" name="username" placeholder="" readonly value="" class="get-right-name">
		</div>
		<div class="password">
			<label>密码</label>
			<input type="text" name="password" placeholder="" maxlength="8" minlength="6" readonly>
			<span class="reset-password get-right-name">修改</span>
		</div>
		<section class="set-new-password set-new-hide">
			<div class="username">
				<label>旧密码</label>
				<input type="password" name="password1" placeholder="请输入旧密码" maxlength="8" minlength="6">
			</div>
			<div class="password">
				<label>新密码</label>
				<input type="password" name="password2" placeholder="请输入新密码" maxlength="8" minlength="6">
			</div>
			<div class="true-password">
				确认修改
			</div>
		</section>
	</div>
	<div class="login-bottom">
		<a href="javascript:;" class="out">退出登录</a>
	</div>
</div>
<div class="search-box searchide"></div>
<script type="text/javascript">
	$(function(){
		// 显示错误信息弹框
	    function layerMsg(msg){
	        layer.open({
	            content: msg,
	            style: 'background-color:rgba(0,0,0,1); color:#fff; border:none;',
	            time: 3
	        }); 
	    }
		$(".reset-password").on("click",function(){
			if($(".set-new-password").hasClass('set-new-hide')){
				$(".set-new-password").removeClass("set-new-hide");
				$(".login-bottom").hide();
			}else{
				$(".set-new-password").addClass("set-new-hide");
				$(".login-bottom").show();
			}
		})
		$(".true-password").on("click",function(){
			var password1 = $.trim($('input[name=password1]').val());
	    	var password2 = $.trim($('input[name=password2]').val());
	    	var reg = /^[0-9a-zA-Z]+$/;
	    	if(password1 == '' || password2 == '' || reg.test(password1) == false || reg.test(password1) == false){
	    		layerMsg('请填写正确的密码');
	    	}else{
	    		$.ajax({
                    url: window.baseUrl+'api/user/updatePassword' ,
                    type: 'POST',
                    data: {
                    	oldPassword:password1,
                    	newPassword:password2
                    },
                    beforeSend: function (XMLHttpRequest) {
		         		XMLHttpRequest.setRequestHeader("token", $.cookie('token_access'));
		            },
                    success: function (data) {
                        if(data.code == '200'){
                        	layerMsg('密码修改成功');
                        }else{
                        	layerMsg(data.message);
                        }
                    }
                });
	    	}
		})
		var id = $.cookie("id");
	    var token = $.cookie('token_access');
	    if(token != undefined){
	        $.ajax({
	          url: window.baseUrl+'api/user/info',
	          type: 'get',
	          data:{
	            id : id,
	            token : token
	          },
	          success: function (data) {
	          	console.log(data)
	              // 个人中心列表
	              $(".username .get-right-name").val(data.datas.customer.username);
	          }
	        });
	    }else{
	      window.location.href="login.html";
	    }
	    function clearAllCookie() {
			var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
			if(keys) {
				for(var i = keys.length; i--;)
					document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
			}
		}
	    $(".out").on("click",function(){
	    	clearAllCookie();
	    	window.location.href="login.html"
	    })
	})
</script>
</body>
</html>